package com.wanaofu.service;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import com.wanaofu.dao.QueryDAO;
import com.wanaofu.dao.UniversalDAO;
import com.wanaofu.model.ProductInfo;

@Service
@Validated
public class ProductService {
	@Resource
	private UniversalDAO uidDAO ;
	@Resource
	private QueryDAO queryDao ;
	
	public List<ProductInfo> getAllProducts() {
		return (List<ProductInfo>)queryDao.getAll(ProductInfo.class);
	}
	
	public void createProductInfo(@NotNull(message="Input must not be null or empty.")ProductInfo p)  {
		uidDAO.save(p);
	}
	public void maintainProductInfo(@NotNull(message="Input must not be null or empty.")ProductInfo p)  {
		uidDAO.update(p);
	}
	public boolean exitsProduct(String pCode) {
		return queryDao.findProductInfoByCode(pCode)==null?false:true ;
	}
	
	public ProductInfo getProductInfoByCode(String pCode) {
		return queryDao.findProductInfoByCode(pCode);
	}
	
	public ProductInfo getProductInfoById(String id) {
		return queryDao.findEntityByID(ProductInfo.class, id);
	}
}	